package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.Price;
import com.ruoyi.system.service.IPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 座位价格
 * Controller
 *
 * @author ...
 * @date 2022-03-17
 */
@RestController
@RequestMapping("/system/price")
public class PriceController extends BaseController {
    @Autowired
    private IPriceService priceService;

    /**
     * 查询座位价格
     * 列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Price price) {
        startPage();
        List<Price> list = priceService.selectPriceList(price);
        return getDataTable(list);
    }

    /**
     * 获取座位价格详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(priceService.selectPriceById(id));
    }

    /**
     * 新增座位价格
     */
    @PostMapping
    public AjaxResult add(@RequestBody Price price) {
        price.setCreateUser(SecurityUtils.getUserId().intValue());
        price.setCreateTime(DateUtils.getNowDate());
        return toAjax(priceService.insertPrice(price));
    }

    /**
     * 修改座位价格
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Price price) {
        price.setUpdateUser(SecurityUtils.getUserId().intValue());
        price.setUpdateTime(DateUtils.getNowDate());
        return toAjax(priceService.updatePrice(price));
    }

    /**
     * 删除座位价格
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(priceService.deletePriceByIds(ids));
    }
}
